<script setup>
import { ref } from 'vue'
import MonthCom from '@/views/work/component/month.vue'
import { useRouter } from 'vue-router'
import request from '@/utils/request'
import dayjs from 'dayjs'
import { useLoginUserStore } from '@/stores'
import { storeToRefs } from 'pinia'
const { loginUserInfo } = storeToRefs(useLoginUserStore())
const router = useRouter()
//返回上一级
const onBackClick = () => {
  router.go(-1)
}
//接收日期组件数据方法
const work_time_month = ref(dayjs().format('YYYY-MM'))
const workloadList = ref([])

const getWorkList = () => {
  request({
    url: '/punchingCardRecord/getList',
    method: 'get',
    params: {
      month: dayjs(work_time_month.value).format('MM'),
      userId: loginUserInfo.value.id,
      year: dayjs(work_time_month.value).format('YYYY')
    }
  })
    .then((res) => {
      console.log('res', res)
      workloadList.value = res.data
    })
    .catch((err) => {})
}
getWorkList()

const onChangeTime = (newTime) => {
  work_time_month.value = newTime
  console.log('work_time_month.value', work_time_month.value)
  getWorkList()
}
</script>
<template>
  <div class="user_homepage">
    <nut-navbar class="homepage_navbar" left-show @click-back="onBackClick">
      <template #left>
        <div>考勤记录</div>
      </template>
    </nut-navbar>
    <MonthCom :work_time_month="work_time_month" @onChangeTime="onChangeTime" />
    <el-table :data="workloadList" stripe height="450" style="width: 100%">
      <!-- 作用域插槽，可以自己拿到想要的数据 -->
      <!-- <el-table-column label="时间" prop="punchCardDate"></el-table-column> -->
      <el-table-column label="状态" prop="punchCardState"></el-table-column>
      <el-table-column label="打卡时间" prop="clockIn">
        <template #default="scope">
          <div>
            {{
              scope.row.clockIn != null
                ? dayjs(scope.row.clockIn).format('YYYY-MM-DD HH:mm:ss')
                : ''
            }}
          </div>
        </template>
      </el-table-column>
      <template #empty>
        <el-empty description="没有数据" />
      </template>
    </el-table>
  </div>
</template>
<style lang="scss" scoped>
.user_homepage {
  .homepage_navbar {
    :deep(.nut-navbar__left) {
      padding: 0px;
      font-size: 16px;
      color: #3b3b3b !important;
    }
    :deep(.nut-icon-left) {
      color: #3b3b3b !important;
    }
  }
  .homepage_group {
    .unity {
      display: flex;
      justify-content: space-between;
    }
    .uesr_img {
      .user_left_title {
        height: 32px;
        line-height: 32px;
      }
    }
  }
}
</style>
